'''

#homework2

def is_anagram(str1,str2):
    list_str1 = list(str1)
    list_str1.sort()
    list_str2 = list(str2)
    list_str2.sort()

    return list_str1 == list_str2


print(is_anagram("anagram","nagaram"))
print(is_anagram('cat','rat'))'''


#homework3

import math

pos = [0,0]
while True:
    s = input()
    if not s:
        break
    if s == "STOP":
        break
    movement = s.split(" ")
    direction = movement[0]
    steps = int(movement[1])
    if direction == "UP":
        pos[0] += steps
    elif direction == "DOWN":
        pos[0] -=steps
    elif direction == "LEFT":
        pos[1] -= steps
    elif direction =="RIGHT":
        pos[1] += steps
    else:
        pass

print(int(round(math.sqrt(pos[1] ** 2 + pos[0] ** 2))))





